home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_300 / 316_01 / as8.doc < prev    next >
Text File  |  1990-05-14  |  10KB  |  472 lines

  1.         AS8, a Z8 Crossassembler
  2.         ========================
  3.  
  4.     by:    H.-G. Willers
  5.         Gartenstrasse 11
  6.         D-8047 Karlsfeld
  7.         WEST GERMANY
  8.  
  9.  
  10.         This document dated 11-jan-90
  11.  
  12.  
  13.             Intro
  14.             =====
  15.  
  16.     This document briefly describes the features
  17.     of my crossassembler for the Z8 microprocessor,
  18.     called AS8.
  19.  
  20.     This assembler is based on some code found in
  21.     a crossassembler for the Z80 microprocessor as
  22.     published on the DECUS tape 11-SP-18.
  23.     The code was polished up (e.g. adding a hashtable
  24.     for the symbols instead of linear search) and
  25.     many bugs were fixed.
  26.  
  27.     The resulting code acts as a skeleton for my
  28.     assemblers like this one: AS8.
  29.  
  30.     The source code was compiled, using:
  31.  
  32.     o  Mark Williams Let's C (Vers. 3.0.2)
  33.  
  34.     o  Microsoft QuickC (Vers. 1.01)
  35.  
  36.     o  System 5.3 UNIX C for 68020
  37.  
  38.     o  Interactive UNIX 386 3.2 2.1
  39.  
  40.     To compile and link under Mark Williams C the file
  41.     'time.c' contains some hacks to simulate the missing
  42.     library functions.
  43.  
  44.  
  45.     The code is provided on an 'as is' basis.
  46.  
  47.     No responsibility for any malfunction of the
  48.     assembler per se or any assembled program can
  49.     be taken. You use it at your own risk.
  50.  
  51.     Please send comments and improvements to the
  52.     author at the above address.
  53.  
  54.  
  55.  
  56.         Commandline Syntax
  57.         ==================
  58.  
  59.     AS8 is invoked by the following commandline:
  60.  
  61.     as8 [-nl] sourcefile.ext
  62.  
  63.     The options mean:
  64.  
  65.     -l    generates a listing named sourcefile.l
  66.  
  67.     -n    do not generate an object file
  68.  
  69.     In the process of producing a name for the
  70.     object file or the listing file the extension
  71.     of the sourcefile is stripped. Any possible
  72.     restrictions of filename use in a given
  73.     operating system may apply.    
  74.  
  75.  
  76.         Source Syntax
  77.         =============
  78.  
  79.     The syntax of a source line for AS8 is as follows:
  80.     
  81.     label:    opc    src, dst    / comment
  82.  
  83.     The 'label' is optional; if used, it must be followed
  84.     by a colon.
  85.  
  86.     'Opc' is the memonic representation for the
  87.     instruction to be used.
  88.  
  89.     The source and destination operands are written
  90.     as source first, then destination.
  91.  
  92.     Comments are introduced by the character '/'.
  93.  
  94.     Multiple statements per line are separated by ';',
  95.     for example:    nop ; nop ; nop
  96.  
  97.  
  98.         Symbols
  99.         =======
  100.  
  101.     A symbol in as8 is a entity with a label set by
  102.     a label or a direct assignment. The number of
  103.     characters per symbol is 33 as distributed.
  104.     It can be changed by adjusting the defined
  105.     constant 'NCPS' to the desired value.
  106.  
  107.     Symbols can consist of the characters of
  108.     the ASCII character set, but must begin with either
  109.     a-z, A-Z, or the characters '.' or '_' (see
  110.     the routine 'isidc(c)' ).
  111.  
  112.         Local Labels
  113.         ============
  114.  
  115.     There are 9 local labels: 1 - 9. references in the
  116.     forward direction are indicated by a 'f', appended
  117.     to the label number, references backwards are
  118.     indicated by a trailing 'b'.
  119.     For example:
  120.  
  121.     1:    nop
  122.         sob    w16,1b        / label 1 backwards
  123.         ...
  124.  
  125.         call    2f        / label 2 forward
  126.         ...
  127.  
  128.     2:    ret
  129.  
  130.     Each local label is reassigned to its new value
  131.     when reused.
  132.  
  133.  
  134.         Number Representation
  135.         =====================
  136.  
  137.     The default radix is decimal. The allowed digits
  138.     range from 0 - 9.
  139.  
  140.     Base 16 numbers (hex) are denoted by a leading '0x'.
  141.     For example: 0x20 is the same as 32.
  142.  
  143.     Base 8 numbers (octal) are denoted by a leading '0'.
  144.     For example:  012 is the value of the ascii character CR.
  145.  
  146.     Base 2 numbers are preceeded by a '0B'.
  147.     For example:  0B01010101 is the same as 0x55.
  148.  
  149.  
  150.  
  151.         Literals
  152.         ========
  153.  
  154.  
  155.     Literal constants are enterd by the character ' ,
  156.     followed by the desired ASCII character.
  157.  
  158.  
  159.  
  160.         Expressions
  161.         ===========
  162.  
  163.     Expressions are made up from numbers (or symbols)
  164.     and arithmetic operators.
  165.  
  166.     Expression evaluation is done from left to right.
  167.     This order can be changed by parenthesis with '[ .. ]'.
  168.  
  169.     The binary arithmetic operators are + , -, *, and %.
  170.     The operator '%' in AS8 means / ( because comments
  171.     are introduced by '/' ).
  172.  
  173.     The bitwise logical operators are
  174.  
  175.         &   bitwise AND
  176.         |   bitwise inclusive OR
  177.         ^   bitwise exclusive OR
  178.         >   right shift
  179.         <   left shift
  180.  
  181.     The following unary operators are supported:
  182.  
  183.         -   two's complement
  184.         !   one's complement
  185.  
  186.  
  187.  
  188.         Pseudo Operators
  189.         ================
  190.  
  191.  
  192.     .byte    symbol
  193.  
  194.     Generates one byte consisting of the value of 'symbol'.
  195.  
  196.     Example:
  197.  
  198.     .byte    0x20        / one byte (ascii space)
  199.  
  200.  
  201.     .word    symbol
  202.  
  203.     Generates one word consisting of the value of 'symbol'.
  204.     The word is generated with the byte ordering of the Z8:
  205.     nameley the upper 8 bits first (big endian byte ordering).
  206.  
  207.     Example:
  208.  
  209.     .word    0x1000        / generates the bytes 0x10 and 0
  210.  
  211.  
  212.     .ascii    string
  213.  
  214.     Generates the named string as a sequence of ascii characters.
  215.     The first character of the string is taken as a terminator.
  216.     The string ends, when the terminator is found again.
  217.  
  218.     Example:
  219.  
  220.     .ascii    "Hi there!"    / ascii string
  221.  
  222.  
  223.     .asciz    string
  224.  
  225.     Generates the named string as a sequence of ascii characters.
  226.     The string is followed by a null-character. The first character
  227.     of the string is taken as a terminator.    The string ends, when
  228.     the terminator is found again.
  229.  
  230.     Example:
  231.  
  232.     .asciz    "Hi there!"    / ascii string with trailing zero
  233.  
  234.  
  235.     .blkb    count [, value]
  236.  
  237.     Space for 'count' bytes is left free. If the optional 'value'
  238.     is not given, null bytes are taken for filling; bytes
  239.     with the 'value' are taken otherwise.
  240.  
  241.     Examples:
  242.  
  243.     .blkb    100, 0x20    / 100 (decimal) bytes of content 0x20
  244.                 / are filled up
  245.     .blkb    0x1000        / 4096 bytes of content 0
  246.  
  247.  
  248.     .page
  249.  
  250.     The listing is advanced by one page.
  251.  
  252.  
  253.     .title    string
  254.  
  255.     The title line for the listing is set. The string starts
  256.     with a terminator, which also end the string.
  257.  
  258.     Example:
  259.  
  260.     .title    "simple demo"
  261.  
  262.  
  263.     .hlist
  264.  
  265.     Sets the radix for number output in the listing to
  266.     hex.
  267.  
  268.  
  269.     .olist
  270.  
  271.     Sets the radix for number output in the listing to
  272.     octal.
  273.  
  274.  
  275.     .list
  276.  
  277.     Starts listing generation. This is the default state.
  278.  
  279.  
  280.     .nlist
  281.  
  282.     Stops listing generation.
  283.  
  284.  
  285.     .end    symbol
  286.  
  287.     The entrypoint of the loaded program is set to 'symbol'.
  288.     The start record of the produced intel-hex-tape is set
  289.     to this value.
  290.  
  291.     Example:
  292.  
  293.     .end    _main        / program starts at _main
  294.  
  295.  
  296.  
  297.         Location Counter
  298.         ================
  299.  
  300.     The location counter is set by the assignment of '.' to
  301.     the desired value.
  302.  
  303.     Example:
  304.  
  305.     .    =    0x1000        / sets the location counter
  306.                     / to 0x1000
  307.  
  308.  
  309.         Addressing Modes
  310.         ================
  311.  
  312.     (See file z8tst.z8 for clarification)
  313.  
  314.     Register:        r0 - r255
  315.  
  316.     Working Register:    w0 - w15
  317.  
  318.     Register Indirect:    e.g. ...  (r0)
  319.  
  320.     Working Register Ind.:    e.g. ...  (w6)
  321.  
  322.     Indexed:        e.g.    mov  r100(w0),w1
  323.  
  324.     Immediate:        e.g.    add  $1,w0
  325.  
  326.     Direct, relative    indicated by a label
  327.  
  328.  
  329.  
  330.         Instruction Description
  331.         =======================
  332.  
  333.     AS8    ZILOG      switch in 'xasm'    base opcode
  334.     ---    -----      ----------------
  335.  
  336.     ccf    ccf        S_OP0        0xef
  337.     di    di        S_OP0        0x8f
  338.     ei    ei        S_OP0        0x9f
  339.     reti    iret        S_OP0        0xbf
  340.     nop    nop        S_OP0        0xff
  341.     rcf    rcf        S_OP0        0xcf
  342.     ret    ret        S_OP0        0xaf
  343.     scf    scf        S_OP0        0xdf
  344.  
  345.     srp    srp        S_OP2        0x31
  346.  
  347.     clr    clr        S_OP3        0xb0
  348.     com    com        S_OP3        0x60
  349.     da    da        S_OP3        0x40
  350.     dec    dec        S_OP3        0
  351.     pop    pop        S_OP3        0x50
  352.     push    push        S_OP3        0x70
  353.     rl    rl        S_OP3        0x90
  354.     rlc    rlc        S_OP3        0x10
  355.     rr    rr        S_OP3        0xe0
  356.     rrc    rrc        S_OP3        0xc0
  357.     sra    sra        S_OP3        0xd0
  358.     swap    swap        S_OP3        0xf0
  359.  
  360.     call    call        S_OP4
  361.  
  362.     jmp    jp  DA        S_OP5        0x8d
  363.     jcs    jp  c,DA    S_OP5        0x7d
  364.     jcc    jp  nc,DA    S_OP5        0xfd
  365.     jeq    jp  z,DA    S_OP5        0x6d
  366.     jne    jp  nz,DA    S_OP5        0xed
  367.     jpl    jp  pl,DA    S_OP5        0xdd
  368.     jmi    jp  mi,DA    S_OP5        0x5d
  369.     jov    jp  ov,DA    S_OP5        0x4d
  370.     jnov    jp  nov,DA    S_OP5        0xcd
  371.     jge    jp  ge,DA    S_OP5        0x9d
  372.     jlt    jp  lt,DA    S_OP5        0x1d
  373.     jgt    jp  gt,DA    S_OP5        0xad
  374.     jle    jp  le,DA    S_OP5        0x2d
  375.     juge    jp  uge,DA    S_OP5        0xfd
  376.     jult    jp  ult,DA    S_OP5        0x7d
  377.     jugt    jp  ugt,DA    S_OP5        0xbd
  378.     jule    jp  ule,DA    S_OP5        0x3d
  379.  
  380.     br    jr  DA        S_OP6        0x8b
  381.     bcs    jr  c,DA    S_OP6        0x7b
  382.     bcc    jr  nc,DA    S_OP6        0xfb
  383.     beq    jr  z,DA    S_OP6        0x6b
  384.     bne    jr  nz,DA    S_OP6        0xeb
  385.     bpl    jr  pl,DA    S_OP6        0xdb
  386.     bmi    jr  mi,DA    S_OP6        0x5b
  387.     bov    jr  ov,DA    S_OP6        0x4b
  388.     bnov    jr  nov,DA    S_OP6        0xcb
  389.     bge    jr  ge,DA    S_OP6        0x9b
  390.     blt    jr  lt,DA